<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Fenxiao extends User_Controller {

	public function __construct()
    {
        parent::__construct();
        // Your own constructor code
        $this->smarty->assign("menu", "fenxiao");
    }

    /**
     * 我的下级同学
     * @return [type] [description]
     */
    function index($level = 1,$limit = 0){

    	$this->load->model('User_model');
    	$this->smarty->assign("level",$level);
    	$this->smarty->assign("user_id",$this->user_data['id']);

    	//获取我的一级同学
    	if($level == 1){
    		$sub_user = $this->User_model->get_user_by_parent1($this->user_data['id'],$limit , 10);
    	}elseif($level == 2){
    		$sub_user = $this->User_model->get_user_by_parent2($this->user_data['id'],$limit , 10);
    	}elseif($level == 3){
    		$sub_user = $this->User_model->get_user_by_parent3($this->user_data['id'],$limit , 10);
    	}


    	$this->smarty->assign("sub_user", $sub_user['result']);
    	// $this->smarty->assign("sub1_user_count", $sub_user['total_count']);
    	/**
    	//获取我的二级同学
    	$sub2_user = $this->User_model->get_user_by_parent2($this->user_data['id']);
    	$this->smarty->assign("sub1_user", $sub2_user['result']);
    	$this->smarty->assign("sub1_user_count", $sub2_user['total_count']);

    	//获取我的三级同学
    	$sub3_user = $this->User_model->get_user_by_parent3($this->user_data['id']);
    	$this->smarty->assign("sub1_user", $sub3_user['result']);
    	$this->smarty->assign("sub1_user_count", $sub3_user['total_count']);
    	**/

    	//获取我的上级
    	$curr_user = $this->User_model->get_user_by_id($this->user_data['id']);
    	$parent_user = $this->User_model->get_user_by_id($curr_user['parent1']);
		$this->smarty->assign("parent_user",$parent_user);

		//获取学校信息
		$this->load->model('School_model');
		$school = $this->School_model->get_school_by_id($this->school_id);
		$this->smarty->assign("school", $school);

    	
		$this->smarty->display("user/fx_index.html");
    }

	function reward(){

		$this->smarty->assign("menu", "fenxiao");
		$this->smarty->display("user/fx_wallet.html");
	}

	/**
	 * 分销订单
	 * @return [type] [description]
	 */
	function order($limit=0){
		//取用户账户信息
		$this->load->model('User_model');
		$user_account = $this->User_model->get_user_account_by_id($this->user_data['id']);
		$this->smarty->assign("user_account",$user_account);

		//获取分销订单
		// $this->load->model('Order_model');
		// $order_result = $this->Order_model->get_fx_order_list_by_user($this->user_data['id'],$limit,10);
		// $this->smarty->assign("order",$order_result['result']);
		//查询用户佣金明细
        $commission_list  = $this->User_model->get_commission_by_user($this->user_data['id']);
        $this->smarty->assign("commission_list", $commission_list);

		$this->smarty->display("user/fx_order.html");
	}

    function user_share($limit = 0){
        $this->load->model('User_model');
        $share_list = $this->User_model->get_user_share_list($limit, $this->offset);

        $this->load->library('pagination');
        $page_config['base_url'] = '/user/fenxiao/user_share';
        $page_config['total_rows'] = $share_list['total_count'];
        $page_config['per_page'] = $this->offset;
        $page_config['uri_segment'] = 4;
        $this->pagination->initialize($page_config);
        $pagination = $this->pagination->create_links();
        $this->smarty->assign("pagination", $pagination);

        $this->smarty->assign("share_list", $share_list['result']);
        $this->smarty->display("user/user_share.html");
    }
}
